const App = getApp();
import siteinfo from '../../../siteinfo';

Page({

  /**
   * 页面的初始数据
   */
  data: {
    // 选项卡标示
    dataType: 'not_use',

    // 列表高度
    swiperHeight: 0,

    // 列表
    list: [],

    // show
    notcont: false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    // 设置swiper的高度
    this.setSwiperHeight();
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    // 获取优惠券列表
    this.GetUserBaoMingList();
  },

  /**
   * 获取优惠券列表
   */
  GetUserBaoMingList: function () {
    let _this = this
    App._post_form('DuiHuanHis', {
      status: 0
    }, (res) => {
      console.log(res)
      for(let i in res){
        res[i].img = siteinfo.siteroot+res[i].lipin.Image
      }
      _this.setData({
        list: res,
        notcont: false
      });
    })
  },
  /**
   * 设置swiper的高度
   */
  setSwiperHeight: function () {
    // 获取系统信息(拿到屏幕宽度)
    let systemInfo = wx.getSystemInfoSync(),
      rpx = systemInfo.windowWidth / 750, // 计算rpx
      tapHeight = Math.floor(rpx * 80) + 1, // tap高度
      swiperHeight = systemInfo.windowHeight - tapHeight; // swiper高度
    this.setData({
      swiperHeight
    });
  },

  /** 
   * 点击tab切换 
   */
  swichNav: function (e) {
    let _this = this;
    _this.setData({
      list: {},
      dataType: e.target.dataset.current
    }, function () {
      // 获取优惠券列表
      let status = 0;
      switch (e.target.dataset.current) {
        case 'not_use':
          status = 0;
          break;
        case 'is_use':
          status = 1;
          break;
        case 'is_expire':
          status = 2;
          break;
        case 'is_jieshu':
          status = 3;
          break;
      }
      App._post_form('GetUserBaoMingList', {
        status: status
      }, (res) => {
        _this.setData({
          list: res,
          notcont: false
        });
      })
    });
  },
  go(e){
    console.log(e)
    wx.navigateTo({
      url: '/pages/detail/index?id='+e.currentTarget.dataset.id,
    })
  }

});